# 基础镜像（含Python+Selenium）
FROM selenium/standalone-chrome:latest

# 安装Python环境
USER root
# 导入阿里云 GPG 密钥
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 0E98404D386FA1D9 6ED0E7B82643E131 F8D2585B8783D481
# 使用阿里云镜像源
RUN echo "deb http://mirrors.aliyun.com/debian/ bookworm main non-free contrib" > /etc/apt/sources.list \
    && echo "deb-src http://mirrors.aliyun.com/debian/ bookworm main non-free contrib" >> /etc/apt/sources.list
# 安装 Python 3.11 和 pip
RUN apt-get update && apt-get install -y python3.11 python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/*

# 设置容器内的工作目录为 /app
WORKDIR /app
# 将当前目录下的所有文件复制到容器的工作目录
# 通常是 Dockerfile 所在的目录中的所有文件复制到容器的 /app 目录中。
COPY . /app

# 安装依赖
ENV PIP_INDEX_URL=https://pypi.doubanio.com/simple
RUN pip install --no-cache-dir -r requirements.txt

# 在安装Allure命令行工具之前添加
RUN apt-get update && apt-get install -y wget

# 安装Allure命令行工具
RUN wget -q https://repo1.maven.org/maven2/io/qameta/allure/allure-commandline/2.13.1/allure-commandline-2.13.1.tgz \
    && tar xzf allure-commandline-2.13.1.tgz -C /opt \
    && rm allure-commandline-2.13.1.tgz

# 将 Allure 添加到 PATH
ENV PATH="/opt/allure-commandline-2.13.1/bin:${PATH}"

# 指定容器启动时运行的命令
# ENTRYPOINT ["sh", "-c"]
# CMD ["sh", "-c", "java -jar /opt/selenium/selenium-server-standalone.jar & sleep 10 && pytest --alluredir=./allure-results"]
CMD ["sh", "-c", "java -jar /opt/selenium/selenium-server-standalone.jar > /app/selenium.log 2>&1 & sleep 10 && pytest --alluredir=./allure-results > /app/pytest.log 2>&1 && tail -f /dev/null &"]